#!/bin/bash

while : ; do
    read CPU USER SYSTEM NICE IDLE IOWAIT IRQ SOFTIRQ STEAL GUEST XXX < /proc/stat
    echo $(date +"%Y-%m-%d %H:%M:%S"),$((USER-USERp)),$((SYSTEM-SYSTEMp)),$((NICE-NICEp)),$((IDLE-IDLEp)),$((IOWAIT-IOWAITp)),$((IRQ-IRQp)),$((SOFTIRQ-SOFTIRQp)),$((STEAL-STEALp)),$((GUEST-GUESTp))
    USERp=$USER
    SYSTEMp=$SYSTEM
    NICEp=$NICE
    IDLEp=$IDLE
    IOWAITp=$IOWAIT
    IRQp=$IRQ
    SOFTIRQp=$SOFTIRQ
    STEALp=$STEAL
    GUESTp=$GUEST
    sleep 10
done
